package com.cqeec.myblog.controller;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.cqeec.myblog.model.Album;
import com.cqeec.myblog.service.AlbumService;
import com.cqeec.myblog.service.AlbumServiceImpl;

@WebServlet("/album/index.html")
public class AlbumServlet extends HttpServlet {
	private static final long serialVersionUID = 3052265148056398968L;
	private AlbumService albumService = new AlbumServiceImpl();

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doGet(req, resp);
	}

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// 获取相册信息
		List<Album> list = null;
		try {
			// 获取服务器中项目根目录下data的绝对路径
			String dataPath = req.getServletContext().getRealPath("/data");
			list = albumService.getAllAlbum(dataPath);
		} catch (Exception e) {
			e.printStackTrace();
		}
		req.setAttribute("list", list);
		req.getRequestDispatcher("../album.jsp").forward(req, resp);
	}

}
